package com.hong.proxy;

import net.sf.cglib.proxy.Enhancer;

public class Demo3 {
	public static void main(String[] args) {
		/**
		 *  目标是让目标对象和增强都可以切换！
		 */
		//创建工厂
		ProxyFactory factory = new ProxyFactory();
		//设置目标对象
		factory.setTargetObject(new ManWaiter());
		factory.setBeforeAdvice(() -> System.out.println("您好不好！"));
		factory.setAfterAdvice(() -> System.out.println("再见不见！"));

		Waiter waiter = (Waiter)factory.createProxy();
		waiter.shouQian();

		Enhancer enhancer = new Enhancer();
		enhancer.setSuperclass(Requestable.class);
		enhancer.setCallback(new RequestCtrlClallback());
		Requestable proxy = (Requestable) enhancer.create();
		proxy.request();
	}

}
